﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Secams.utils
{
    class TypeConverter
    {
        public static object fromString(Type type, string strVal)
        {
            object retval = null;
            if (type == typeof(string))
                retval = strVal;
            else if (type == typeof(int))
                retval = int.Parse(strVal);
            else if (type == typeof(float))
                retval = float.Parse(strVal);
            else if (type == typeof(short))
                retval = short.Parse(strVal);
            else if (type == typeof(double))
                retval = double.Parse(strVal);
            else if (type == typeof(bool))
            {
                if (strVal != null)
                {
                    if ("1".Equals(strVal) || "true".Equals(strVal.ToLower())
                         || "yes".Equals(strVal.ToLower()))
                        retval = true;
                    else
                        retval = false;
                }
            }
            return retval;
        }
    }
}
